﻿
using HandyControl.Tools;
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace LpbPrj.Client.Tools.Converter
{
    public class FixLampConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null || parameter == null) return null;

            try
            {
                int index = System.Convert.ToInt32(value);
                int count = System.Convert.ToInt32(parameter);

                string str = $"FixLamp{count}_{index}";
                return Application.Current.FindResource(str);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }

            return null;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

    public class FixLampBackgroundConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var output = ResourceHelper.GetResource<System.Windows.Media.Brush>("BackgroundBrush");
            if (value == null || parameter == null) return output;

            {
                if (value is int input)
                {
                    int index = System.Convert.ToInt32(parameter);
                    output = input == index ? ResourceHelper.GetResource<System.Windows.Media.Brush>("SelectedHighlightBorderBrush") : ResourceHelper.GetResource<System.Windows.Media.Brush>("BackgroundBrush");
                }
            }

            return output;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
